<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>定时任务新增</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">

    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">任务名称</label>
        <div class="layui-input-block">
            <input type="text" name="jobName" lay-verify="required" lay-reqtext="任务名不能为空"
                   placeholder="请输入任务名称" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">调用分组</label>
        <div class="layui-input-block">
            <select name="jobGroup" id="jobGroup" lay-filter="jobGroup">
                <option th:each="item: ${sysJobGroupDict}" th:text="${item.name}"
                        th:value="${item.code}"></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">调用方法<i class="layui-icon layui-icon-about" id="layui-icon-about"></i></label>
        <div class="layui-input-block">
            <input type="text" name="invokeTarget" lay-verify="required" lay-reqtext="请输入调用方法"
                   placeholder="请输入调用方法" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">cron表达式</label>
        <div class="layui-input-inline">
            <input type="text" name="cronExpression" lay-verify="required" lay-reqtext="请输入cron表达式"
                   placeholder="请输入cron表达式" value="" class="layui-input">
        </div>

        <div class="layui-form-mid layui-word-aux">
            <button class="layui-btn layui-btn-xs layui-btn-normal" id="generateCron">cron生成器</button>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">是否并发执行</label>
        <div class="layui-input-block">
            <input type="radio" name="concurrent" value="0" title="允许" checked>
            <input type="radio" name="concurrent" value="1" title="禁止">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">错误策略</label>
        <div class="layui-input-block">
            <input type="radio" name="misfirePolicy" value="1" title="立即执行" checked>
            <input type="radio" name="misfirePolicy" value="2" title="执行一次">
            <input type="radio" name="misfirePolicy" value="3" title="放弃执行">
        </div>
    </div>

    <!-- 右侧悬浮按钮 -->
    <div class="right-bottom-btn">
        <button class="layui-btn" lay-submit lay-filter="saveBtn">
            <i class="layui-icon layui-icon-ok"></i>确认
        </button>
        <button class="layui-btn" lay-filter="cancleBtn">
            <i class="layui-icon layui-icon-close"></i>取消
        </button>
    </div>
</div>
<script th:src="@{/lib/jquery-3.4.1/jquery-3.4.1.min.js}" charset="utf-8"></script>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/lib/coco-message/coco-message.js}" charset="utf-8"></script>
<script th:src="@{/js/lay-config.js}" charset="utf-8"></script>
<script type="text/javascript" th:inline="javascript">
    AjaxUtil.ctx = /*[[@{/}]]*/'';
    layui.use(['form', 'layer'], function () {
        var form = layui.form,
            layer = layui.layer;

        var tipStr = "<p>Bean调用示例：bluewindTask.bwParams('嘿嘿')</p>" +
            "<p>Class类调用示例：com.bluewind.boot.module.timertask.BluewindTask.bwParams('嘿嘿')</p>" +
            "<p>参数说明：支持字符串，布尔类型，长整型，浮点型，整型</p>";

        var tipsIndex;
        $("#layui-icon-about").on("mouseover", function() {
            tipsIndex = layer.tips(tipStr, "#layui-icon-about", {tips: [1, '#4BB2FF'], time: 50000});
        }).on("mouseout", function() {
            layer.close(tipsIndex);
        });


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert('确认提交吗？', function () {
                var loading = layer.load(0, {shade: 0.1});
                AjaxUtil.post({
                    url: AjaxUtil.ctx + "job/add",
                    data: data.field,
                    success: function (res) {
                        if (res.code === 0) {
                            layer.close(index);
                            layer.close(loading);
                            Message.success(1500, res.message, function () {
                                // 重载表格
                                var iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                            });
                        } else {
                            layer.close(loading);
                            Message.error(res.message, 1000);
                        }
                    },
                    error: function (error) {
                    }
                });
            });
            return false;
        });

        form.verify({
            classname: [
                /^[a-zA-Z]+(\.([a-zA-Z])+)+$/
                , '请填写正确的调用目标'
            ]
        });


        // 调出Cron表达式生成器页面
        $("#generateCron").click(function () {
            var index = layer.open({
                title: 'Cron表达式生成器',
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: [(layerwidth - 40) + 'px', (layerheight - 100) + 'px'],
                content: AjaxUtil.ctx + 'job/forCron',
                end: function (index) {
                    // 重载表格

                }
            });
        });


        // 监听取消按钮
        $("button[lay-filter='cancleBtn']").click(function(){
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
        });
    });
    
    function getChildValue(obj) {
        console.log(obj);
        $("input[name='cronExpression']").val(obj);
    }
</script>
</body>
</html>